// pages/component/timeItemTemp/timeItemTemp.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    device:{
      type:Object,
      value:undefined
    },
    isTiming:{
      type:Boolean,
      value:false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    /**
     * 为了获取checkbox点击,只能用数组包装数据,checkbox外面也必须用checkbox-group包裹(因为其有绑定事件的方法),
     * 作为添加一条新定时的过渡页,实际上该页面永远只有一个数据
     */
    // timings:[{    
    //   // startTime: '00:00',
    //   // endTime: '00:00',
    //   // isTiming: false
    // }]
    startTime: '00:00',
    endTime: '00:00',
    isTiming: false
    
  },

  /**
   * 组件的方法列表
   */
  methods: {
    reset:function(){
      var _this=this;
   
      _this.setData({ startTime: "00:00", endTime: "00:00", isTiming: false });
    },
    addCancle:function(event){
      // console.log("点击删除按钮  " + JSON.stringify(event));
      var _this = this;
      var e = {
      }
      _this.triggerEvent('addCancle', e, '');
      _this.reset();
    },
    addConfirm: function (event) {
      // console.log("点击删除按钮  " + JSON.stringify(event));
      var _this = this;
      var device=_this.data.device;
      var e = {
        data:{
          dId:device.id,
          // startTime: Date.parse(new Date(_this.data.timings[0].startTime)),
          // endTime: Date.parse(new Date(_this.data.timings[0].endTime)),

          // startTime: new Date(_this.data.timings[0].startTime),
          // endTime: new Date(_this.data.timings[0].endTime),

          startTime: "1970-01-01 "+_this.data.startTime+":00",
          endTime: "1970-01-01 " + _this.data.endTime + ":00",
          gSerial: device.gSerial,
          controllerAddr: device.controllerAddr,
          deviceAddr: device.deviceAddr,
          isTiming: _this.data.isTiming
        }

      }
      _this.triggerEvent('addConfirm', e, '');
      _this.reset();
      
    },
    timingUsingCheck:function(event){
        var _this=this;
        // console.log("是否启用事件详情:"+JSON.stringify(event));
      // var timings = _this.data.timings;
      // _this.data.isTiming = event.detail.value.length != 0;
      _this.setData({ isTiming: event.detail.value.length != 0 });
      
    },
    bindStartTimeChange: function (event) {
      var _this = this;
      // console.log('picker发送选择改变，携带值为', event.detail.value)
      // var timings = _this.data.timings;
      // _this.data.startTime = event.detail.value;
      _this.setData({ startTime: event.detail.value });
      
      // this.setData({
      //   time: event.detail.value
      // });
    },
    bindEndTimeChange: function (event) {
      var _this = this;
      // console.log('picker发送选择改变，携带值为', event.detail.value)
      // var timings = _this.data.timings;
      // _this.data.endTime = event.detail.value;
      _this.setData({ endTime: event.detail.value });

      // this.setData({
      //   time: event.detail.value
      // });
    }
  }
})
